// 浏览器的前进后退功能
// 面向对象模块化，一个文件就写一个类
// 引入其他模块
const { StackBasedLinkedList } = require('./StackBaseOnLinkedList');
class Browser {
    constructor() {
        this.normalStack = new StackBasedLinkedList();
        this.backStack = new StackBasedLinkedList();
    }
    pushNormal(name) {
        this.normalStack.push(name);
        this.backStack.clear();
        this.displayAllstack();
    }
    back() {
        const value = this.normalStack.pop();
        if (value !== -1) {
            // 可以
            this.backStack.push(value);
            this.displayAllstack();
        } else {
            // 到达栈底
            console.log('无法后退......');
        }
        this.backStack.push();
    }
    front() {
        const value = this.backStack.pop();
        if (value !== -1) {
            this.normalStack.push(value);
            this.displayAllstack();
        } else {
            console.log('无法前进');
        }
    }
    displayAllstack() {
        console.log('---后退页面---');
        this.backStack.display();
        console.log('---浏览页面---');
        this.normalStack.display();
    }
}
let browser = new Browser();
browser.pushNormal('www.google.com');
browser.pushNormal('www.baidu.com');
browser.pushNormal('www.github.com');
browser.back();
// browser.back();
browser.front();
browser.pushNormal('www.tmall.com');